<?php

namespace app\admin\model\xmwms;

use think\Model;

/**
 * Unit
 */
class Unit extends Model
{
    // 表名
    protected $name = 'wms_unit';

    /**
     * @var string 自动写入时间戳字段
     */
    protected $autoWriteTimestamp = true;

    // 字段类型转换
    protected $type = [
        'deletetime' => 'timestamp:Y-m-d H:i:s',
    ];

    protected static function onAfterInsert($model)
    {
        if ($model->weigh == 0) {
            $pk = $model->getPk();
            $model->where($pk, $model[$pk])->update(['weigh' => $model[$pk]]);
        }
    }
}